package com.qst.survey.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qst.survey.entity.Question;
import org.apache.ibatis.annotations.Select;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Update;

import javax.validation.constraints.Min;
import java.util.List;

/**
 * @Date: 2021/3/18 13:50
 * @Description: 问卷映射类
 */
public interface QuestionMapper extends BaseMapper<Question> {
    @Select("select\n" +
            "       question.id,\n" +
            "       user_id,\n" +
            "       theme,\n" +
            "       content,\n" +
            "       create_time,\n" +
            "       update_time,\n" +
            "       is_over,\n" +
            "       Type.msg,\n" +
            "       over_time\n" +
            "from question,Type\n" +
            "where  question.Type=Type.id\n" +
            "and question.deleted=0\n" +
            "and question.Type=#{type}")
    Page<Question> selectQuestionPageByType(Page<Question> page, int type);

    @Update("update question set topic_numb = question.topic_numb + 1 where id = #{questionId}")
    void topicNumbPlusOne(Integer questionId);


    @Select("select * from question where deleted=1 and user_id =#{questionId}")
    List<Question> findAllDelete(Integer questionId);

    @Update("update question set deleted = 0 where id=#{id}")
    Integer restoreQuestion(Integer id);

}
